﻿using Bouyei.Geo.Geometries;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Bouyei.Geo.GeoParsers.GeoJson
{
    public class GeometryWriter
    {
        public string ToWriter(Geometry geometry)
        {
            if (geometry.GeometryType == GeoType.POINT
                || geometry.GeometryType == GeoType.POINTZ)
            {
                return new GeoJsonPoint(geometry).FromGeometry();
            }
            else if (geometry.GeometryType == GeoType.MULTIPOINT)
            {
                return new GeoJsonMultiPoint(geometry).FromGeometry();
            }
            else if (geometry.GeometryType == GeoType.LINESTRING
                || geometry.GeometryType == GeoType.LINESTRINGZ)
            {
                return new GeoJsonLineString(geometry).FromGeometry();
            }
            else if (geometry.GeometryType == GeoType.MULTILINESTRING)
            {
                return new GeoJsonMultiLineString(geometry).FromGeometry();
            }
            else if (geometry.GeometryType == GeoType.POLYGON
               || geometry.GeometryType == GeoType.POLYGONZ)
            {
                return new GeoJsonPolygon(geometry).FromGeometry();
            }
            else if (geometry.GeometryType == GeoType.MULTIPOLYGON)
            {
                return new GeoJsonMultiPolygon(geometry).FromGeometry();
            }
            else
            {
                throw new Exception("not supported:" + geometry.GeometryType);
            }
        }

        public string ToWriter<T>(Feature<T,PointArray>[] features)
            where T:class
        {
            FeatureCollection<T> f = new FeatureCollection<T>();
            return f.ToGeoJsonString(features);
        }

        public string ToWriter<T>(Feature<T, PointMArray>[] features)
         where T : class
        {
            FeatureCollection<T> f = new FeatureCollection<T>();
            return f.ToGeoJsonString(features);
        }

        public string ToWriter<T>(Feature<T, LineArray>[] features)
       where T : class
        {
            FeatureCollection<T> f = new FeatureCollection<T>();
            return f.ToGeoJsonString(features);
        }

        public string ToWriter<T>(Feature<T, LineMArray>[] features)
        where T : class
        {
            FeatureCollection<T> f = new FeatureCollection<T>();
            return f.ToGeoJsonString(features);
        }

        public string ToWriter<T>(Feature<T, PolygonArray>[] features)
 where T : class
        {
            FeatureCollection<T> f = new FeatureCollection<T>();
            return f.ToGeoJsonString(features);
        }

        public string ToWriter<T>(Feature<T, PolygonMArray>[] features)
where T : class
        {
            FeatureCollection<T> f = new FeatureCollection<T>();
            return f.ToGeoJsonString(features);
        }
    }
}
